#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef unsigned long long LL;
#define endl '\n'
LL f[20];
void solve() 
{
    string s; LL x; cin >> s >> x;
    vector<string> ret;
    string tmp;
    for(auto ch : s)
    {
        if(ch == '+') 
        {
            ret.push_back(tmp);
            tmp = "";
        }
        else tmp += ch;
    }
    ret.push_back(tmp);
    // for(auto t : ret) cout << t << endl;
    LL a = 0, b = 0, c = 0, d = 0;
    bool f1 = 1, f2 = 1, f3 = 1, f4 = 1;
    for(auto& t : ret)
    {
        
        for(int i = 0; i < t.size(); i++)
        {
            int pos = t.size() - 1 - i;
            if(pos <= 18)
            {
                if(t[i] == 'G') 
                {
                    if(f1) 
                    {
                        a += f[pos];
                        if(a > x) f1 = 0;
                    }
                    
                }
                else if(t[i] == 'D') 
                {
                    if(f2) 
                    {
                        b += f[pos];
                        if(b > x) f2 = 0;
                    }
                }
                else if(t[i] == 'U')
                {
                    if(f3) 
                    {
                        c += f[pos];
                        if(c > x) f3 = 0;
                    }
                }
                else if(t[i] == 'T') 
                {
                    if(f4)
                    {
                        d += f[pos];
                        if(d > x) f4 = 0;
                    }
                }
            }
            else
            {
                if(t[i] == 'G') f1 = 0;
                else if(t[i] == 'D') f2 = 0;
                else if(t[i] == 'U') f3 = 0;
                else if(t[i] == 'T') f4 = 0;
            }
        }
    }
    if(!f1) a = 0; if(!f2) b = 0; if(!f3) c = 0; if(!f4) d = 0; 
    // cout << a << " " << b << " " << c << " " << d << endl;
    for(int i = 0; i <= 9; i++)
    {
        for(int j = 0; j <= 9; j++)
        {
            for(int k = 0; k <= 9; k++)
            {
                for(int p = 0; p <= 9; p++)
                { 
                    LL sum = i * a + j * b + k * c + p * d;
                    if(sum == x)
                    {
                        // cout << i << " " << j << " " << k << ' ' << p << " " << endl;
                        // cout << a << " " << b << " " << c << " " << d << endl;
                        // cout << (i * a + j * b + k * c + p * d) << endl;
                        cout << "Yes\n";
                        cout << (f1 ? i : 0) << " "
                             << (f2 ? j : 0) << " "
                             << (f3 ? k : 0) << " "
                             << (f4 ? p : 0) << "\n"; 
                        return;
                    }
                }
            }
        }
    }
    cout << "No\n";
}

int main()
{
    f[0] = 1;
    for(int i = 1;i <= 18; i++) f[i] = f[i - 1] * 10;
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int T;
	cin >> T;
	while(T--)
	{
        solve();
	}
	return 0;
}